#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>



MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    userinfo=new vector<pair<QString,QString>>;
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
    delete userinfo;
}


void MainWindow::on_signin_clicked()
{
    int exist=0;
    vector<pair<QString,QString>> t=*userinfo;
    qDebug()<<t.size()<<(*userinfo).size();
    for(int i=0;i<(this->userinfo->size())&&t.size()>0;i++,t.pop_back()){
        if(ui->user->text()==t.back().first){
            exist=1;
            break;
        }
    }
    if(exist){
        if(ui->passwd->text()==t.back().second){
            qDebug()<<"登陆成功";
        }else{
            qDebug()<<"账号密码有误";
        }
    }else{
        qDebug()<<"该用户未注册";
    }

}

void MainWindow::on_signup_clicked()
{
    QString* useraccount=new QString();
    QString* passwd=new QString();
    *useraccount=ui->user->text();
    *passwd=ui->passwd->text();
    pair<QString,QString> p=make_pair(*useraccount,*passwd);
    this->userinfo->push_back(p);
    qDebug()<<*useraccount<<*passwd;
}
